package main

import (
	"fmt"
	"sync"
)

var (
	counter int
	lock    sync.Mutex
)

func increment() {
	lock.Lock() // Before accessing the shared variable, lock the mutex.
	counter++
	lock.Unlock() // After accessing the shared variable, unlock the mutex.
}

func main() {
	var wg sync.WaitGroup

	for i := 0; i < 10000; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			increment()
		}()
	}

	wg.Wait()
	fmt.Println("Final counter value:", counter)
}
